# Install dependencies only when needed
FROM node:18.18.2-alpine AS deps
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn config set network-timeout 300000
RUN yarn install --frozen-lockfile
RUN yarn config set registry https://registry.npmmirror.com/

# Rebuild the source code only when needed
FROM node:18.18.2-alpine AS runner
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY package.json ./package.json
COPY index.js ./index.js
COPY src ./src

ENV NODE_ENV production

ENV HOST=0.0.0.0
EXPOSE 20001
CMD ["yarn", "start"]
